import React from 'react'
import Search from '../../components/search.jsx'
import Carousel from '../../components/Carousel.jsx'
import Sort from '../../components/Sort.jsx'
import Shop from '../../components/Shop.jsx'
import './index.less'

class Index extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            imgUrl: null,
            tuijian: [
                { title: '只能已发送', money: '111' },
                { title: '只能已发送', money: '111' },
                { title: '只能已发送', money: '111' }
            ],
            ShopData: null,
        }
        console.log(this.props)
    }
    after() { }
    componentDidMount() {
        this.$getData('/api/sowingMap/getPhoneSowing', params => {
            switch (params.code) {
                case 100:
                    this.setState({
                        imgUrl: params.data
                    })
                    break;
                default:
                    this.Toast.info(params.msg);
                    break;
            }
        })
        this.$getData('/api/homeGoods/getHomeGoods', params => {
            switch (params.code) {
                case 100:
                    console.log(params.data)
                    this.setState({
                        ShopData: params.data
                    })
                    break;
                default:
                    this.Toast.info(params.msg);
                    break;
            }
        })
    }

    componentWillUnmount() {
        // this.refs.btn.onclick = null;
        // this.off('$getData', this.$getData);
        this.$getData = null;
    }
    render() {
        return (
            <div className='Index-page'>
                <Search></Search>
                <Carousel after={this.after.bind(this)} dots={true} imgHeight={'45vw'} data={this.state.imgUrl}></Carousel>
                <Sort></Sort>
                {this.state.ShopData ? this.state.ShopData.map((val, index) => (
                    <div key={index}>
                        <p className='index-p1 index-p2'>{val.typeName}</p>
                        <div className='index-d1'>{val.voList.map(val => (<Shop key={val.commonId} data={val}></Shop>))}</div>
                        {console.log(val.voList)}
                    </div>
                )) : ''}
            </div>
        )
    }
}

export default (Index)